package com.hnxxxy.jfmgr.service.Impl;

import com.hnxxxy.common.AjaxRtnEntity.AjaxRtnEntity;
import com.hnxxxy.jfmgr.mapper.JfTestimonialsAuditMapper;
import com.hnxxxy.jfmgr.pojo.Jf_detail;
import com.hnxxxy.jfmgr.service.JfTestimonialsAuditService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;

@Service
@Slf4j
public class JfTestimonialsAuditServiceImpl implements JfTestimonialsAuditService {
    @Autowired
    JfTestimonialsAuditMapper jfTestimonialsAuditMapper;

    @Override
    public List<Jf_detail> findAllTestimonialsAudit(Jf_detail jf_detail) {
//        按角色放Status
//        Subject subject = SecurityUtils.getSubject();
//        Staff staff = (Staff) subject.getPrincipal();
//        subject.get
        jf_detail.setStatus(1);
        return jfTestimonialsAuditMapper.findAllTestimonialsAudit(jf_detail);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public int updateTestimonialsAudit(Jf_detail jf_detail) {
        try {

            jfTestimonialsAuditMapper.updateTestimonialsAudit();
            return AjaxRtnEntity.success;
        } catch (Exception e) {
            log.info("-->用户奖状上传状态删除异常：" + e.toString());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxRtnEntity.error;
        }
    }
}
